package com.software.graduationproject.commons.util;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;

import java.util.Date;

/**
 * 时间工具类
 */
public class DateUtils {
    public static final String TIME_FORMAT       = "yyyy-MM-dd HH:mm:ss";
    public static final String HOUR_START_FORMAT = "yyyy-MM-dd HH:00:00";
    public static final String DAY_FORMAT        = "yyyy-MM-dd";
    public static final String MONTH_DAY_FORMAT  = "MM-dd";
    public static final String MONTH_FORMAT      = "yyyy-MM";
    public static final String YEAR_FORMAT       = "yyyy";

    public static DateTime formatDateToDateTime(Date date) {
        // 将 Date 格式化为字符串
        String formattedDate = DateUtil.format(date, TIME_FORMAT);
        // 将格式化后的字符串解析为 DateTime 对象
        DateTime dateTime = DateUtil.parse(formattedDate);
        return dateTime;
    }

    public static Date formatDateToDate(Date date) {
        // 将 Date 格式化为字符串
        String formattedDate = DateUtil.format(date, DAY_FORMAT);
        // 将格式化后的字符串解析为 DateTime 对象
        Date dateTime = DateUtil.parse(formattedDate);
        return dateTime;
    }
}
